﻿using System;

namespace HelloWorld
{
    class Hello
    {
        public Hello() { }
        public void readOnlyTest()
        {
            God god = new God(100, 200);
            god.Compare();
        }

        public void ForeachTest()
        {
            int[] aa = { 1, 2, 3, 4, 5 }; 

            foreach (var i in aa)
            {
                Console.WriteLine(i + $": {i.GetType()}");
            }
        }

        public class God
        {
            private int power;     // 上帝的力气
            private readonly int stoneWeight; // 石头的重量
            public God(int power, int stoneWeight)
            {
                this.power = power;
                this.stoneWeight = stoneWeight;
            }

            public void Compare()
            {
                if(power >= stoneWeight)
                {
                    Console.WriteLine("上帝可以举起石头！");
                } else
                {
                    Console.WriteLine("上帝不能举起石头！");
                }
            }

            public void Change()
            {
                power = 100;
                //stoneWeight = 100;        // 无法修改
            }
        }

        public void CaseTest(int i)
        {   // 强制break;
            switch (i)
            {
                case 1:
                    Console.WriteLine("1");
                    break;
                default:
                    Console.WriteLine("default");
                    break;
                case 5:
                    Console.WriteLine("我是你爹！");
                    break;
            } 
        }

        private void ConstTest()
        {   // 常量不可修改
            const int k = 100;
            Console.WriteLine(k);
        }

        public int VarTest()
        {   // var产生类型推断
            var name = "法外狂徒张三";
            var age = 108;
            var isBadBoy = true;

            Console.WriteLine($"name is {name.GetType()}");
            Console.WriteLine($"age is {age.GetType()}");
            Console.WriteLine($"isBadBoy is {isBadBoy.GetType()}");
            return 0;
        } 
    }
}
